#include <57header.h>

/* Usage: ./03_dup filename */
int main(int argc, char *argv[]){
    ARGS_CHECK(argc, 2);
    int old_fd = open(argv[1], O_RDWR);
    ERROR_CHECK(old_fd, -1, "open");
    printf("old_fd = %d\n", old_fd);

    int new_fd = dup(old_fd);
    ERROR_CHECK(new_fd, -1, "dup");
    printf("new_fd = %d\n", new_fd);

    // 利用这两个文件描述符进行写操作

    write(old_fd, "hello", 5);
    write(new_fd, "kitty", 5);

    close(old_fd);
    close(new_fd);
    return 0;
}

